string.cases.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 1
rs 10
1
 /**
2
 * Transform to lowercase.
3
 * @playground
4
 * var toLowerCase = require('strman').toLowerCase;
5
 * let title = "A Javascript string manipulation library.";
6
 * let result = toLowerCase(title);
7
 * @param {String} value - The String!.
8
 * @return {String} - String in lowercase.
9
 */
10
const toLowerCase = value => value.toLowerCase();
11
12
export {toLowerCase};
13
14
/**
15
 * Transform to uppercase.
16
 * @playground
17
 * var toUpperCase = require('strman').toUpperCase;
18
 * let title = "A Javascript string manipulation library.";
19
 * let result = toUpperCase(title);
20
 * @param {String} value - The String!.
21
 * @return {String} - String in uppercase.
22
 */
23
const toUpperCase = value => value.toUpperCase();
24
25
export {toUpperCase};
26
27
 /**
28
 * Verify if has lowerCase
29
 * @playground
30
 * var isLowerCase = require('strman').isLowerCase;
31
 * let title = "A Javascript string manipulation library.";
32
 * let result = isLowerCase(title);
33
 * @param {String} value - The String!.
34
 * @return {Boolean} - String is lowercase?.
35
 */
36
const isLowerCase = (value) => value === toLowerCase(value);
37
38
export {isLowerCase};
39
 
40
 /**
41
 * Verify if has UPPERCASE
42
 * @playground
43
 * var isUpperCase = require('strman').isUpperCase;
44
 * let title = "A Javascript string manipulation library.";
45
 * let result = isUpperCase(title);
46
 * @param {String} value - The String!.
47
 * @return {Boolean} - String is UPPERCASE?.
48
 */
49
const isUpperCase = (value) => value === toUpperCase(value);
50
51
export {isUpperCase};
52
53
/**
54
 * Transform to StudlyCaps.
55
 * @playground
56
 * var toStudlyCaps = require('strman').toStudlyCaps;
57
 * let title = "A Javascript string manipulation library.";
58
 * let result = toStudlyCaps(title);
59
 * @param {String} value - The String!.
60
 * @return {String} - String in StudlyCaps.
61
 */
62
const toStudlyCaps = value => {
63
    let string = value.replace(/[\-_\s]+(.)?/g,
64
                            (match, chr) => chr ? toUpperCase(chr) : '');
65
    return toUpperCase(string.substr(0, 1)) + string.substr(1);
66
};
67
68
export {toStudlyCaps};
69
70
/**
71
 * Transform to camelCase.
72
 * @playground
73
 * var toCamelCase = require('strman').toCamelCase;
74
 * let title = "A Javascript string manipulation library.";
75
 * let result = toCamelCase(title);
76
 * @param {String} value - The String!.
77
 * @return {String} - String in camelCase.
78
 */
79
const toCamelCase = value => {
80
    let string = toStudlyCaps(value);
81
    return toLowerCase(string.substr(0, 1)) + string.substr(1);
82
};
83
84
export {toCamelCase};
85
86
 /**
87
 * Decamelize String
88
 * @playground
89
 * var toDecamelize = require('strman').toDecamelize;
90
 * let title = "A Javascript string manipulation library.";
91
 * let result = toDecamelize(title);
92
 * @param {String} value - The String!.
93
 * @return {String} - String decamelized.
94
 */
95
const toDecamelize = (value, chr = '_') => {
96
    let camel = toCamelCase(value);
97
    let string = camel.replace(/([A-Z])+/g, chr + '$1');
98
    return toLowerCase(string);
99
};
100
101
export {toDecamelize};
102
103
/**
104
 * Transform to snake_case.
105
 * @playground
106
 * var toSnakeCase = require('strman').toSnakeCase;
107
 * let title = "A Javascript string manipulation library.";
108
 * let result = toSnakeCase(title);
109
 * @param {String} value - The String!.
110
 * @return {String} - String in snake_case.
111
 */
112
const toSnakeCase = value => {
113
    return toDecamelize(value, '_');
114
};
115
116
export {toSnakeCase};
117
118
/**
119
 * Transform to kebab-case.
120
 * @playground
121
 * var toKebabCase = require('strman').toKebabCase;
122
 * let title = "A Javascript string manipulation library.";
123
 * let result = toKebabCase(title);
124
 * @param {String} value - The String!.
125
 * @return {String} - String in kebab-case.
126
 */
127
const toKebabCase = value => {
128
    return toDecamelize(value, '-');
129
};
130
131
export {toKebabCase};
132